<template>
    <!--小微课堂-->
    <div class="contain">
        <div class="product-header">
            <div class="option-tip">最近更新</div>
            <ul class="video-list">
                <li v-for="(item, index) in topVideoList" :key="index" @click="handleJumpToVideo(item)">
                    <div class="video-face-warp">
                        <img :src="item.vid_img_url" alt=""/>
                    </div>
                    <div class="video-title">
                        <span style="color: white">{{ item.name }}</span>>
                    </div>
                </li>
            </ul>
        </div>
        <div class="main-box">
            <div class="header">
                <a-dropdown class="dropdown-item">
                    <a class="ant-dropdown-link" @click="e => e.preventDefault()">
                        {{ hoverText }}
                        <a-icon type="down"/>
                    </a>
                    <a-menu slot="overlay">
                        <a-menu-item v-for="(item,index) in hoverArray" :key="index"
                                     @click="chooseItem(item,'hoverText')">
                            <a class="hover-item" :class="item.text==hoverText?'active':''">{{ item.text }}</a>
                        </a-menu-item>
                    </a-menu>
                </a-dropdown>
                <a-dropdown class="dropdown-item">
                    <a class="ant-dropdown-link" @click="e => e.preventDefault()">
                        {{ hotText }}
                        <a-icon type="down"/>
                    </a>
                    <a-menu slot="overlay">
                        <a-menu-item v-for="(item,index) in hotArray" :key="index" @click="chooseItem(item,'hotText')">
                            <a class="hover-item" :class="item.text==hotText?'active':''">{{ item.text }}</a>
                        </a-menu-item>
                    </a-menu>
                </a-dropdown>
                <div class="play-his">播放记录</div>
            </div>
            <div
                v-infinite-scroll="handleInfiniteOnLoad"
                class="demo-infinite-container"
                :infinite-scroll-disabled="busy"
                :infinite-scroll-distance="10"
            >
                <a-list :data-source="data" class="course-list">
                    <a-list-item class="li" slot="renderItem" slot-scope="course" @click="handleJumpToVideo(course)">
                        <div class="intro-left">
                            <div class="video-face-warp">
                                <img :src="course.vid_img_url" alt=""/>
                            </div>
                        </div>
                        <div class="intro-content">
                            <div class="title">{{ course.name || title }}</div>
                            <div class="content">{{ course.video_desc || desc }}</div>
                            <div class="tag-box">
                                <div class="tag">{{ course.first_lab_name }}</div>
                            </div>
                            <div class="footer-intro">
                                <i class="icon-user"> </i>
                                讲师：{{ course.tname }}
                                <i class="split-line"></i>
                                所属项目：{{ course.xmname }}
                                <i class="split-line"></i>
                                时长：{{ course.shic }}
                                <i class="split-line"></i>
                            </div>
                        </div>
                    </a-list-item>
                    <div v-if="loading && !busy" class="demo-loading-container">
                        <a-spin/>
                    </div>
                </a-list>
            </div>
        </div>
    </div>
</template>
<script>
import infiniteScroll from 'vue-infinite-scroll';

export default {
    name: 'LittleClassroom',
    directives: {infiniteScroll},
    data() {
        return {
            account: '',
            topVideoList: [{video_url: ''}],
            courseList: [{video_url: ''}],
            hoverArray: [{type: 'ALL', text: 'CMA'}, {type: '1', text: 'CPA'}, {type: '2', text: 'MPACC'}],
            hotArray: [{type: 0, text: '全部'}, {type: 1, text: '最新'}, {type: 2, text: '最热'}],
            hotId: 0,
            hotText: '全部',
            hoverText: 'CMR',
            data: [],
            loading: false,
            busy: false,
            pageIndex: 1

        };
    },
    watch: {
        /**/
    },
    beforeMount() {

    },
    mounted() {
        /**/
        this.getWxspZx()
        // this.getXwspCon('ALL', 0, 1, 6);
        this.getXwspCon('ALL', this.hotId, this.pageIndex, 6).then(res => {
            console.log(res);
            this.data = res;
        });
    },
    methods: {
        handleInfiniteOnLoad() {
            this.loading = true;
            this.pageIndex++;
            this.getXwspCon('ALL', this.hotId, this.pageIndex, 6).then(res => {
                console.log(res);
                if (!res) {
                    this.$message.warning('数据已加载完');
                    this.busy = true;
                    this.loading = false;
                    return;
                }
                this.data = this.data.concat(res);
                this.loading = false;
            });
        },
        chooseItem(item, type) {
            console.log(item);
            this[type] = item.text;
            if (type == 'hoverText') {
                this.hoverId = item.type;
            } else {
                if (item.type == this.hotId) return
                this.hotId = item.type;
                this.pageIndex = 1;
                this.getXwspCon('ALL', this.hotId, this.pageIndex, 6).then(res => {
                    console.log(res);
                    this.data = res;
                });

            }
        },
        /*小微课堂-最新4个*/
        getWxspZx() {
            this.$api.ajaxData({
                pathName: 'getXwspZx',
                authorization: true
            }).then(res => {
                this.topVideoList = res.obj
            })
        },
        getXwspCon(flbname, hot, page, size) {
            return new Promise((resolve) => {
                this.$api.ajaxData({
                    method: 'POST',
                    pathName: 'getXwspCon',
                    authorization: true,
                    data: {
                        flbname: flbname,
                        hot: hot,
                        page: page,
                        size: size
                    }

                }).then(res => {
                    console.log(res);
                    resolve(res.obj)
                })
            })

        },
        //打开视频详情页
        handleJumpToVideo(video) {
            this.$router.push({
                name: 'video',
                query: {
                    title: video.name,
                    type: 4,
                    vid: video.vid,
                    url: encodeURI(video.video_url)
                }
            })
        }
    }
};
</script>
<style scoped lang="scss">
.contain {
    .product-header {
        position: relative;
        padding: 30px 0;
        color: #fff;

        .option-tip {
            position: relative;
            width: 248px;
            height: 31px;
            line-height: 31px;
            margin: 0 auto 30px;
            background: inherit;
            background-color: rgba(51, 51, 51, 0.5);
            border: none;
            border-radius: 10px;
            -moz-box-shadow: none;
            -webkit-box-shadow: none;
            box-shadow: none;
            text-align: center;
            font-weight: 700;
            font-style: normal;
            font-size: 16px;
            color: #FFFFFF;
        }

        .video-list {
            display: flex;
            width: 1200px;
            margin: 0 auto;
            font-size: 13px;
            justify-content: space-between;

            li {
                position: relative;
                width: 250px;
                height: 140px;
                background: #292929;

                .video-face-warp {
                    width: 250px;
                    height: 140px;
                    background: #000;

                    img {
                        width: 100%;
                        height: 100%;
                    }
                }

                .video-title {
                    position: absolute;
                    bottom: 0;
                    width: 100%;
                    height: 35px;
                    line-height: 35px;
                    text-align: center;
                    font-weight: bold;
                    background: rgba(0, 0, 0, 0.5);
                }

                &:after {
                    content: '';
                    position: absolute;
                    top: 50%;
                    left: 50%;
                    display: block;
                    width: 40px;
                    height: 40px;
                    background: url("../../assets/image/icon/u1526_mouseOver.png") no-repeat;
                    background-size: cover;
                    transform: translate(-50%, -50%);
                }
            }
        }

        &:before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100%;
            margin-left: calc(50% - 50vw);
            background: url('../../assets/image/back/u542.jpg') no-repeat;
            background-size: 100% 100%;
        }
    }

    .main-box {
        .header {
            padding: 30px;

            .play-his {
                float: right;
            }

            .main-text {
                font-size: 24px;
                font-weight: 700;
                margin-right: 40px;
            }

            .child-text {
                font-size: 20px;
                font-weight: 700;
                margin-right: 40px;
            }

            .dropdown-item {
                padding: 10px 50px;
                color: #fff;
                line-height: 1.5;
                font-size: 18px;
                margin-right: 50px;
                background: #0592fe;
                border-radius: 5px;
                box-sizing: border-box;
                .hover-item.active {
                    background-color: #9FBCFB;
                }
            }

        }

        .demo-infinite-container {
            border: 1px solid #e8e8e8;
            border-radius: 4px;
            overflow: auto;
            padding: 8px 24px;
            height: 100vh;
            //height: calc(100vh - 450px);
        }

        .demo-loading-container {
            position: absolute;
            bottom: 40px;
            width: 100%;
            text-align: center;
        }

        .ant-list-item {
            justify-content: flex-start;
        }

        .course-list {
            padding: 30px;
            color: #333;
            font-size: 13px;

            .li, li {
                display: flex;
                padding: 15px;
                margin: 0 0 20px;
                border-radius: 10px;
                box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1), 0 -3px 10px rgba(0, 0, 0, 0.1);


                .intro-left {
                    position: relative;
                    padding-right: 20px;

                    .video-face-warp {
                        width: 250px;
                        height: 140px;
                        background: #000;

                        img {
                            width: 100%;
                            height: 100%;
                        }
                    }

                    .bottom-status {
                        position: absolute;
                        bottom: 0;
                        width: 100%;
                        height: 45px;
                        padding: 0 10px;
                        line-height: 45px;
                        box-sizing: border-box;
                        color: #fff;
                        background: rgba(255, 255, 255, 0.5);
                    }
                }

                .intro-content {
                    position: relative;
                    min-width: 300px;

                    .title {
                        margin-bottom: 10px;
                        font-size: 16px;
                        font-weight: bold;
                    }

                    .content {
                        height: 40px;
                        color: #666;
                        text-align: justify;
                        @include ellipsis-line;
                    }

                    .tag-box {
                        display: flex;
                        margin-bottom: 20px;

                        .tag {
                            margin-right: 8px;
                            height: 22px;
                            line-height: 22px;
                            padding: 0 10px;
                            border-radius: 11px;
                            font-size: 11px;
                            color: #0079FE;
                            border: 1px solid #0079FE;
                        }
                    }

                    .footer-intro {
                        //position: absolute;
                        //bottom: 0;
                        display: flex;
                        align-items: center;
                        color: #999;

                        .icon-user {
                            display: block;
                            width: 15px;
                            height: 17px;
                            margin-right: 10px;
                            background: url("../../assets/image/icon/u117.png") no-repeat;
                            background-size: contain;
                        }

                        .split-line {
                            height: 14px;
                            width: 1px;
                            margin: 0 12px;
                            background: #cecece;
                        }
                    }
                }
            }
        }
    }
}
</style>
